package org.iks.common.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.lang.Nullable;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * Author kzou
 * Date 2024/1/30
 * Description:
 */
@Slf4j
public class IpUtil {

    /**
     * 获取本地IP地址
     */
    @Nullable
    public static String tryGetLocalIpAddress() {
        try {
            InetAddress localHost = InetAddress.getLocalHost();
            return localHost.getHostAddress();
        } catch (UnknownHostException e) {
            log.warn("get local ip exception {}", e.getMessage());
            return null;
        }
    }

}
